<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <ul>

    </ul>

    <script>

        let oul = document.querySelector('ul');
        //创建ajax
        const ajax = new XMLHttpRequest();
        //配置信息请求
        ajax.open('get', '/shop');
        //发请求
        ajax.send()
        //// 4.监听结果，获取返回的成功结果
        ajax.onreadystatechange = function () {
            if (ajax.readyState == 4 && ajax.status == 200) {
                // console.log(ajax.responseText);
                let data = JSON.parse(ajax.responseText)
                console.log(data);
                //声明一个空字符串
                let str = '';
                //渲染数据
                data.forEach(item => {
                    str += ` <li>
            <h2>商品名：${item.tradeName}</h2>
            <img src="${item.picture}" alt="">
            <p>价格：${item.price}</p>
            <p>数量：${item.stock}</p>
        </li>`
                })

                oul.innerHTML = str;
            }
        }
    </script>
</body>

</html>